//
//  CMDBPicPickerViewCell.swift
//  CMDB
//
//  Created by 曹桂祥 on 17/4/18.
//  Copyright © 2017年 CMDB. All rights reserved.
//

import UIKit

class CMDBPicPickerViewCell: CMDBBaseCollectionViewCell {
    
    var coverImage : UIImageView!
    
    var addButton : UIButton!
    
    var image : UIImage?{
        
        didSet{
            if image != nil {
                coverImage.image = image
                
                addButton.userInteractionEnabled = false
                
            }else{
                coverImage.image = nil
                
                addButton.userInteractionEnabled = true
                
                
            }
        }
        
    }
    
    override func buildCollectionCell() {
        super.buildCollectionCell()
        
        addButton       = UIButton()
        
        addButton.setBackgroundImage(UIImage(named: "上传图片"), forState: .Normal)
        
        addButton.sizeToFit()
        
        addButton.frame = CGRect(x: 0, y: 0, width: width, height: width)
        
        addButton.addTarget(self, action: #selector(addPhotoClick), forControlEvents: .TouchUpInside)
        
        contentView.addSubview(addButton)
        
        coverImage       = UIImageView()
        
        coverImage.frame = CGRect(x: 0, y: 0, width: width, height: width)
        
        contentView.addSubview(coverImage)
        
        
    }
}


extension CMDBPicPickerViewCell{
    
    @objc func addPhotoClick(){
        
        
        mDelegate?.onItemClickType!("AddPhotoClick", data: nil, indexPath: nil)
    }
    
}
